<?php
/*
 * Created on 2012
 * Link for shyflc@qq.com
 * This PHPYun.Rencai System Powered by PHPYun.com
 */
 class cache{
	public $cachedir;
	public $obj;
	public function __construct($cachedir,$obj) {
		$this->cachedir = $cachedir;
		$this->obj=$obj;
		include(LIB_PATH."public.function.php");
	}
	public function city_cache($dir){
		$cityarr=$this->obj->DB_select_all("city_class");
		if(is_array($cityarr)){
			foreach($cityarr as $v){
				if($v[keyid]==0){
					$city_index[]=$v[id];
				}
				if($v[keyid]!=0){
					$city_type[$v[keyid]][]=$v[id];
				}
				$cityname[$v[id]]=$v[name];
			}
		}
		$data[city_index]=ArrayToString($city_index,false);
		$data[city_type]=ArrayToString($city_type);
		$data[city_name]=ArrayToString($cityname);
		return $this->obj->made_web_array($this->cachedir.$dir,$data);
	}
	public function industry_cache($dir){
		$rows=$this->obj->DB_select_all("industry");
		if(is_array($rows)){
			foreach($rows as $v){
				if($v[keyid]==0){
					$industry_index[]=$v[id];
				}
				if($v[keyid]!=0){
					$industry_type[$v[keyid]][]=$v[id];
				}
				$industryname[$v[id]]=$v[name];
			}
		}
		$data[industry_index]=ArrayToString($industry_index,false);
		$data[industry_type]=ArrayToString($industry_type);
		$data[industry_name]=ArrayToString($industryname);
		return $this->obj->made_web_array($this->cachedir.$dir,$data);

	}
	public function job_cache($dir){
		$rows=$this->obj->DB_select_all("job_class");
		if(is_array($rows)){
			foreach($rows as $v){
				if($v[keyid]==0){
					$job_index[]=$v[id];
				}
				if($v[keyid]!=0){
					$jobtype[$v[keyid]][]=$v[id];
				}
				$jobname[$v[id]]=$v[name];
			}
		}
		$data[job_index]=ArrayToString($job_index,false);
		$data[job_type]=ArrayToString($jobtype);
		$data[job_name]=ArrayToString($jobname);
		return $this->obj->made_web_array($this->cachedir.$dir,$data);
	}
	public function user_cache($dir){
		$rows=$this->obj->DB_select_all("userclass","1 order by sort asc");
		if(is_array($rows)){
			foreach($rows as $v){
				if($v[keyid]!=0){
					$com_index[$v["keyid"]][]=$v["id"];
				}
				$jobname[$v[id]]=$v[name];
			}
			foreach($rows as $v){
				if($v[keyid]==0){
					$data2[$v[variable]]=$com_index[$v[id]];
				}
			}
		}
		$data[userdata]=ArrayToString($data2);
		$data[userclass_name]=ArrayToString($jobname);
		return $this->obj->made_web_array($this->cachedir.$dir,$data);

	}
	public function com_cache($dir){
		$rows=$this->obj->DB_select_all("comclass","1 order by sort asc");
		if(is_array($rows)){
			foreach($rows as $v){
				if($v["keyid"]!=0){
					$com_index[$v["keyid"]][]=$v["id"];
				}
				$comname[$v[id]]=$v[name];
			}
			foreach($rows as $v){
				if($v[keyid]==0){
					$data2[$v[variable]]=$com_index[$v[id]];
				}
			}
		}
		$data[comdata]=ArrayToString($data2);
		$data[comclass_name]=ArrayToString($comname);
		return $this->obj->made_web_array($this->cachedir.$dir,$data);
	}
	public function menu_cache($dir){
		$rows=$this->obj->DB_select_all("navigation","display=1 order by sort asc");
		if(is_array($rows)){
			foreach($rows as $key=>$v){
				if(!is_array($com_index[$v["nid"]]))$a[$v["nid"]]=0;
					$com_index[$v["nid"]][$a[$v["nid"]]]['name']=$v["name"];
					$com_index[$v["nid"]][$a[$v["nid"]]]['url']=$v["url"];
					$com_index[$v["nid"]][$a[$v["nid"]]]['eject']=$v["eject"];
					$a[$v["nid"]]++;
			}
		}
		$data[menu_name]=ArrayToString2($com_index);
		return $this->obj->made_web_array($this->cachedir.$dir,$data);
	}
 }

?>